<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

$strcodi = $_REQUEST["txtCodigo"];
$strnomb = $_REQUEST["ATxtNombre"];
$strcaja = $_REQUEST["ATxtCaja"];
$cboTipo = $_REQUEST["cboTipo"];
//$strusua = $_REQUEST["ATxtUsuario"];
//$strclav = $_REQUEST["ATxtClave"];
//$strclv2 = $_REQUEST["ATxtClave"];
//$strperf = $_REQUEST["CmbPerfil"];
$strnodo = $_REQUEST["CboNodo"];
$Opcion = $_REQUEST["Opcion"];
$arrQueries = array();
$arrLogs = array();

$tabla = "TDL_DATOS";
switch($Opcion){
    case 1:
        $tipo = "UPDATE";
        $SoloSQL = "$tipo $tabla set ";
        $SoloSQL .= "campo2='$strnomb',";
        $SoloSQL .= "id_etdl = $cboTipo";
        $SoloSQL .= " where id_tdl_datos = $strcodi";
        array_push($arrQueries, $SoloSQL);
        array_push($arrLogs, crearQueryLog($tabla, $tipo, $SoloSQL));

        $pagina = "organizaciones_Modificar.php";
        $opc = "&Opcion=1&txtCodigo=$strcodi";
        break;
    case 2:
        $tipo = "DELETE";
        $SoloSQL = "UPDATE $tabla SET ";
        $SoloSQL .= "fecha_eliminacion = CURRENT_DATE ";
        $SoloSQL .=  " where id_tdl_datos = $strcodi";
        array_push($arrQueries, $SoloSQL);
        array_push($arrLogs, crearQueryLog($tabla, $tipo, $SoloSQL));
    
        $pagina = "organizaciones_Eliminar.php";
        $opc = "&Opcion=2&txtCodigo=$strcodi";
        break;
    case 3:
        $oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
        $SoloSQL="select (max(id_tdl_datos)+1) as maximo from TDL_DATOS";
        $Maximo = SoloFun_ExecSqlFull($SoloSQL, $Arreglo, $oConexion);
        
        $tipo = "INSERT";
        $SoloSQL = "$tipo into $tabla (id_tdl, id_etdl, campo2, fecha_creacion, id_user) values(";
        $SoloSQL .=  "28, ";
        $SoloSQL .=  "$cboTipo, ";
        $SoloSQL .=  "'$strnomb', ";
        $SoloSQL .=  "'".date("d/m/Y")."', ";
        $SoloSQL .=  "{$_SESSION["id_usua"]})";
        array_push($arrQueries, $SoloSQL);
        array_push($arrLogs, crearQueryLog($tabla, $tipo, $SoloSQL));
//echo $SoloSQL;
        $SoloSQL = "INSERT INTO ORGANIZACION (id_tdl_datos) VALUES ($Maximo)";
        array_push($arrQueries, $SoloSQL);
        array_push($arrLogs, crearQueryLog("ORGANIZACION", "INSERT", $SoloSQL));

        $pagina = "organizaciones_Modificar.php";
        $opc = "&Opcion=3";
        break;
}

$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
if(!$oConexion->EjecutarTransaccion($arrQueries))
    $strMsg = $pagina . "?SoloError=1&CboNodo=$strnodo$opc";
else
    $strMsg = $pagina . "?SoloError=0&CboNodo=$strnodo$opc";
$oConexion->Cerrar();

unset($oConexion);

$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
$oConexion->EjecutarTransaccion($arrLogs);
$oConexion->Cerrar();
//echo $strMsg;
header ("Location: $strMsg");
?>
